// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
//import WechatAuth from 'vue-wechat-auth'
//import Vue from "vue/dist/vue.common.js";
import App from './App'
import router from './router'
import VueScroller from 'vue-scroller'
import 'babel-polyfill'
import 'url-search-params-polyfill';
import axios from 'axios'
Vue.use(VueScroller) //下拉刷新，上拉加载
Vue.prototype.$axios = axios;
// VUEX状态存储
import { sync } from 'vuex-router-sync'
import store from '@/store'
sync(store, router)

// 日期格式化
import Moment from 'moment'
// Vue.use(Moment)
Vue.prototype.moment = Moment

// 引入UI组件
import Mint from 'mint-ui'
import 'mint-ui/lib/style.css'
Vue.use(Mint)

// minirefresh刷新组件
import MiniRefreshTools from 'minirefresh'
import 'minirefresh/dist/debug/minirefresh.css'
Vue.use(MiniRefreshTools)

// 调用手势库
import AlloyFinger from 'alloyfinger/alloy_finger'
import AlloyFingerVue from 'alloyfinger/vue/alloy_finger.vue'
Vue.use(AlloyFingerVue, {
	AlloyFinger
})

Vue.config.productionTip = false

router.afterEach((to,from,next) => {
  window.scrollTo(0,0);
});
import VueCropper from 'vue-cropper' 


import { getCurLocation} from '@/assets/js/common'
Vue.use(VueCropper)
/* eslint-disable no-new */
window.vm = new Vue({
	el: '#app',
	store,
	router,
	render: h => h(App),
	mounted() {
		var that=this
		localStorage.setItem("watchId",0)
		mui.init({
			keyEventBind: {
				backbutton: false
			}
		})
		getCurLocation((p) => { //获取gps坐标 
			that.curPointLat =p.coords.latitude,
		    that.curPointLng =p.coords.longitude
			if(p.coords.latitude){
					var jsonData={
		        	lat:that.curPointLat,
		        	lng:that.curPointLng
		        }
		        localStorage.setItem("location",JSON.stringify(jsonData))
			}
		})
		
		
	    /*function plusReady() { // 获取本地应用资源版本号
			clientid = plus.push.getClientInfo().clientid
			alert(clientid)
			if (!clientid) { //如果获取的cid为空，说明客户端向推送服务器注册还未完成，可以使用setTimeout延时重试。
	      		setTimeout(() => {
	      			clientid = plus.push.getClientInfo().clientid
	      			alert(clientid+',,,,,')
	      		}, 4000)
	      	}
			localStorage.setItem("cid", JSON.stringify(clientid)) //存贮用户信息
		}
		if(window.plus) {
			plusReady();
		} else {
			document.addEventListener('plusready', plusReady, false);
		}*/
		
		/*function pushListener() {
			this.clientid = plus.push.getClientInfo().clientid
			if (!this.clientid) { //如果获取的cid为空，说明客户端向推送服务器注册还未完成，可以使用setTimeout延时重试。
				setTimeout(() => {
					this.clientid = plus.push.getClientInfo().clientid
				}, 4000)
			}
		 
			plus.push.addEventListener('click', (message) => {
				this.pushCallBack()
			});
		 
			plus.push.addEventListener('receive', (message) => {
		        this.pushCallBack()
			});
		}
		 
		function pushCallBack() {
			
		}*/
	    
	    
	    
	},
})
/*export const newStore = localStorage.getItem('vuex') && JSON.parse(localStorage.getItem('vuex'))
console.log(newStore);*/

Vue.filter('handleDistance', function(value) {
	return value = value >= 1000 ? (value / 1000).toFixed(2) + 'km' :value.toFixed(0) + 'm';
})
Vue.filter('handleDistance2', function(value) {
	return value = value >= 1000 ? (value / 1000).toFixed(1) + 'km' :value.toFixed(0)+ 'm';
})
Vue.filter('handleDistance3', function(value) {
	return value = value >= 1000 ? (value / 1000).toFixed(0) + 'km' :value.toFixed(0)+ 'm';
})
Vue.filter('time', function(value) {
	let str = value.substring(0,value.lastIndexOf(':'));
	return str;
})
Vue.filter('Money', function(value) {
	let str = value.toFixed(2);
	return str;
})
Vue.filter('timeZhuan', function(value) {
	value=String(value)
	let str = value.replace(/-/g, ".")
	let str2=str.substring(0,str.lastIndexOf(':'));
	return str2;
})

Vue.filter('toDecimal2', function(value){
  var f = parseFloat(value);
  if (!isNaN(f)) {
    var f = Math.round(value*100)/100;
    var s = f.toString();
    var rs = s.indexOf('.');
    if (rs < 0) {
      rs = s.length;
      s += '.';
    }
    while (s.length <= rs + 2) {
      s += '0';
    }
    return s;
  }
})


Vue.filter('restTime', function(time) {
    let day = parseInt(time / (60 * 60 * 24));
    let hou = parseInt(time % (60 * 60 * 24) / 3600);
    let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
    let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
    if(day>0){
      return day+'天'+hou+'时'+min+'分'+sec+'秒';
    }else if(hou>0){
      return hou+'时'+min+'分'+sec+'秒';
    }else if(min>0){
      return min+'分'+sec+'秒';
    }else{
      return sec+'秒';
    }
})
//图片路径转化为图片地址
Vue.filter("imgPathToUrl", function(path) {
	return stf.img_url + path
});
//截取日期时间
Vue.filter("timeSub", function(item) {
	return item.substring(0,10)
});
 Vue.filter("phones", function(phone) {
	return phone.substring(0, 3) + "****" + phone.substring(7, 11);
});   		
Vue.filter('Distance', function(value) {
	value=(value / 1000).toFixed(1)
	return value 
})
